﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;

namespace AutoR.ViewModels.Setting
{
	// Token: 0x02000091 RID: 145
	public class FriendListViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x170000A0 RID: 160
		// (get) Token: 0x06000295 RID: 661 RVA: 0x00046ADA File Offset: 0x00044CDA
		private INavigationService NavigationService { get; }

		// Token: 0x170000A1 RID: 161
		// (get) Token: 0x06000296 RID: 662 RVA: 0x00046AE2 File Offset: 0x00044CE2
		private IPageDialogService PageDialogService { get; }

		// Token: 0x170000A2 RID: 162
		// (get) Token: 0x06000297 RID: 663 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x170000A3 RID: 163
		// (get) Token: 0x06000298 RID: 664 RVA: 0x00046AEA File Offset: 0x00044CEA
		// (set) Token: 0x06000299 RID: 665 RVA: 0x00046AF4 File Offset: 0x00044CF4
		public ObservableCollection<Friend> List
		{
			[CompilerGenerated]
			get
			{
				return this.<List>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<List>k__BackingField, value))
				{
					return;
				}
				this.<List>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.List);
			}
		}

		// Token: 0x170000A4 RID: 164
		// (get) Token: 0x0600029A RID: 666 RVA: 0x00046B24 File Offset: 0x00044D24
		public DelegateCommand OKCommand { get; }

		// Token: 0x170000A5 RID: 165
		// (get) Token: 0x0600029B RID: 667 RVA: 0x00046B2C File Offset: 0x00044D2C
		// (set) Token: 0x0600029C RID: 668 RVA: 0x00046B34 File Offset: 0x00044D34
		public bool IsBusy
		{
			[CompilerGenerated]
			get
			{
				return this.<IsBusy>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsBusy>k__BackingField == value)
				{
					return;
				}
				this.<IsBusy>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsBusy);
			}
		}

		// Token: 0x0600029D RID: 669 RVA: 0x00046B61 File Offset: 0x00044D61
		public FriendListViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.NavigationService = navigationService;
			this.PageDialogService = pageDialogService;
			this.OKCommand = new DelegateCommand(async delegate()
			{
				this.Game.FriendTask.Friend = (from i in this.List
				where i.IsSelected
				select i.uid).ToList<int>();
				this.Game.FriendTask.StarTime = DateTime.Now;
				await this.NavigationService.GoBackAsync();
			});
		}

		// Token: 0x0600029E RID: 670 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x0600029F RID: 671 RVA: 0x00046B90 File Offset: 0x00044D90
		public async void OnNavigatedTo(INavigationParameters parameters)
		{
			this.IsBusy = true;
			List<Friend> list = await Runtime.Remote.FriendList();
			using (List<Friend>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Friend friend = enumerator.Current;
					if (this.Game.FriendTask.Friend.Any((int i) => i == friend.uid))
					{
						friend.IsSelected = true;
					}
				}
			}
			this.List = new ObservableCollection<Friend>(list);
			foreach (Friend friend2 in list)
			{
				friend2.UserShip = (await Runtime.Remote.FriendVisitor(friend2.uid)).friendFleet;
				await this.Game.Delay(500);
				friend2 = null;
			}
			List<Friend>.Enumerator enumerator2 = default(List<Friend>.Enumerator);
			this.IsBusy = false;
		}

		// Token: 0x060002A0 RID: 672 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}
	}
}
